<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2024/12/10
  Time: 11:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <style>
        body{
            background-color: #f8f9fa;
        }
        .CONTENT{
            width: 100%;
            height: 200px;
            background-color: #fff;
            border-radius: 40px;
            padding: 10px;
            margin-bottom: 20px;
        }
        p{

            width: auto;
            /*padding: 20px;*/
        }
        img{
            width: 200px;
            height: 200px;
            object-fit: cover;
            position: absolute;
            right: 10%;
            /*transform: translateY(-20px);*/
        }
        h1{
            position: absolute;
            width: 50%;
            margin: 0px;
        }
        .TEXT{
            position: absolute;
            transform: translateY(200%);
        }
    </style>
</head>

<body>
<%@ page import="java.sql.*" %>

<%
    String CONTENT = null;
    String TITLE = null;
    String USERID = null;
    String TEXT = null;
    String PICTURE = null;
    ResultSet rs = null;
    int flag = 0;
    PreparedStatement pstmt;

    // 数据库连接信息
    String url = "jdbc:mysql://localhost:3306/db1";
    String user = "root";
    String password = "123456";

    try {
        // 加载驱动
        Class.forName("com.mysql.jdbc.Driver");

        // 建立连接
        Connection conn = DriverManager.getConnection(url, user, password);
//        System.out.println("conn = " + conn);

        // 创建SQL语句
        String sql = "SELECT * FROM upload";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            // 获取查询结果
            TITLE = rs.getString("TITLE");
            CONTENT = rs.getString("CONTENT");
            USERID = rs.getString("USERID");
            TEXT = rs.getString("TEXT");
            PICTURE = rs.getString("PICTURE");

            out.print("<div class='CONTENT'>");
            out.print("<h1>" + TITLE + "</h1>");
            out.print("<div class='TEXT'>");
            out.print(TEXT);
            out.print("</div>");
            out.print(PICTURE);
            out.print("</div>");
        }



//        // 执行SQL语句
//        pstmt.executeUpdate();

        // 关闭连接
        pstmt.close();
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
</body>
<script>
</script>
</html>
